package com.cn.demo4.servlet.admin.company;

import com.alibaba.fastjson.JSONObject;
import com.cn.demo4.service.ICompanyService;
import com.cn.demo4.service.impl.CompanyServiceImpl;
import com.cn.demo4.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/company/del")
public class CompanyDelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        //2.得到前台传递来的id
        String idString = req.getParameter("id");
        //3.封装数据
        Integer id = Tool.stringToInt(idString);

        ICompanyService iCompanyService = new CompanyServiceImpl();

        int result = iCompanyService.del(id);

        //返回结果
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        resp.getWriter().println(jsonObject);
    }
}
